package poounit;
import tec.*;
import java.lang.reflect.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.Class;
import java.util.ArrayList;
import java.io.*;

public class TestRun{
	private static int passed = 0, failed = 0, exception = 0;

	static public void run() throws Exception {

		boolean estMisAssertion = false;
		assert estMisAssertion = true;

		if (!estMisAssertion) 
		{
			System.out.println("Execution impossible sans l'option -ea");
			return;
		}

		ArrayList<String> classPath = new ArrayList<String>();
		classPath.add("tec.TestAutobusException"); 
		classPath.add("tec.TestJaugeNaturelException"); 
		classPath.add("tec.TestPassagerAbstraitException"); 
		classPath.add("tec.TestEtatPassager"); 

		for(String cP : classPath) {
			for (Method m : Class.forName(cP).getMethods()) {
				if (m.isAnnotationPresent(Test.class)) {
					System.out.printf(". ");
					try {
						m.invoke(null);
						passed++;
					} catch (InvocationTargetException e) {
						if(!(e.getTargetException() instanceof AssertionError))
							exception++;

						System.out.println("Test" + m + " failed: "+ e.getCause());
						for(StackTraceElement s : e.getStackTrace())
							System.out.println("\t " + s.toString());
						failed++;
					}
					System.out.printf("\n");
				}
			}
		}
		int total = passed + failed;
		System.out.println("Passed: " + passed +", Failed " + failed + ", Exception " + exception + ", Total " + total);
	}

	public static void  main(String[] args) throws Exception {
			run();
	}
}
